 #include <iostream>
 #include <vector>
 using namespace std;
 
 int main()
 {
	string s1,s2;
	cin>>s1>>s2;
	int ret=1e3*26;
	
	for(int i=0;i<=s2.size()-s1.size();i++)
	{
		int sum=0;
		for(int j=0;j<s1.size();j++)
		{
			char a=s1[j];
			char b=s2[i+j];
			int dif=abs(a-b);
			sum+=min(dif,26-dif);
		}
		ret=min(ret,sum);
	}
	cout<<ret<<endl;
 	return 0;
 }
